<?php
namespace App\Controllers\Coupons;

use App\Models\Activity\Activity;
use App\Models\Coupon\Coupons;
use App\Libs\Views\Json;
/**
    获取优惠券列表
 */
class GetCouponsList extends \App\Libs\Base\BaseAction
{

    public function execute()
    {

        $page = $this->request->getQuery('page','int',1);
        $size = $this->request->getQuery('size','int',10);
        $offset = ($page-1)*$size;
        $allCoupons = Coupons::findAll([
            '1=1',
            'columns'=> 'id,title,full_price,price,is_show',
            'order' => 'is_show desc',
            'offset' => $offset,
            'limit' => $size
        ])->toArray();
        $couponsNum = Coupons::count();
        if(empty($allCoupons)){
            return Json::view(0,'没有更多数据了',['coupons'=>[],'sum'=>$couponsNum]);
        }else{
            return Json::view(0,'ok',['coupons'=>$allCoupons,'sum'=>$couponsNum]);
        }
    }
}
